<?php
/*=============================================================================
|| ##################################################################
||	phpFoX Konsort
|| ##################################################################
||
||	Copyright		: (C) 2005-2007 PHPFOX Limited a Reality Fox Creation
||	Contact			: info@phpfox.com
||
||	- phpFoX and all of its source code and files are protected by Copyright Laws.
||
||	- The license for phpFoX permits you to install this software on a single domain (.com, .org, .net, etc.).
||
||	- You may also not remove this copyright screen which shows the copyright information and credits for phpFoX (RealityFOX Creations).
||
||	- phpFoX Konsort is NOT a FREE software - http://www.phpfox.com/license/
||
|| ##################################################################
=============================================================================*/

/* $File: ./include/modules/Account/classes/PhpFox_ComponentFieldConstructorAdd.class.php, $Author:  $ */



/** User custom fields add component
 *
 * @package module.account
 * @version $Id: PhpFox_ComponentFieldConstructorAdd.class.php 46 2007-12-14 23:12:21Z phpfoxsv $
 *
 */
class PhpFox_Mod_Account_ComponentFieldConstructorAdd extends BaseComponent
{
    /** Processing method
     */
	function process()
	{
	    $oCustomFieldService = &$this->_oModule->getService('CustomField');
	    /* @var $oCustomFieldService PhpFox_Mod_Account_ServiceCustomField */
	    $oReq = &App::getRequest();
	    $oTpl = &$this->_oModule->getTemplate();
	    if (($oReq->getAction() == 'add') && ($sTitle = $oReq->get('title')))
	    {
	        $sDefaultOption = $oReq->get('option');
	        if (!$sDefaultOption)
	        {
	            $sDefaultOption = 'default';
	        }
	        $iPos = $oReq->getInt('pos');
	        $iMaxPos = $oCustomFieldService->getMaxFieldPos();
	        $bRecount = true;
	        if (!$iPos || ($iPos > ($iMaxPos + 1)))
	        {
	            $iPos = $iMaxPos + 1;
	            $bRecount = false;
	        }
	        $sType = $oReq->get('type');
	        $sSignup = $oReq->get('signup');
	        $sPanel = $oReq->get('panel');
	        list($iFieldId, $iDefaultOptionId) = $oCustomFieldService->addNewField($iPos, $sTitle, $sDefaultOption, $sType, $sSignup, $sPanel);
	        if ($bRecount)
	        {
	            $oCustomFieldService->updateFieldPosition($iPos);
	        }
	        Cache::subStrRemove('custom');
	        if ( empty($iDefaultOptionId) )
	        {
				App::gotoUrl('admin.main.custom-fields', array('added' => $iFieldId));
	        }
	        else
	        {
	        	App::gotoUrl('admin.main.custom-fields-option', array('id' => $iFieldId));
	        }
	    }

		if ( $bAdded = $oReq->get('added') )
		{
			$this->oTpl->assign('added', true);
		}

	    return $oTpl->fetch('FieldAdd.html');
	}
}
?>